%convergence && divergence
%**************************************************************************
%----------------------------------------f_id=1 matsuda_tide;
%---------------------------------------------2 ecmwf_tide;
%---------------------------------------------3 last 5 years 2015;
%---------------------------------------------4 last 5 years 2001;
%---------------------------------------------5 first 5 years 2015;
%---------------------------------------------6 ecmwf_notide;
%---------------------------------------------8 matsuda_notide;
%---------------------------------------------9 23.93 ecmwf
%--------------------------------------------10 ecmwf_notide_10*0.0333
%--------------------------------------------12 ecmwf_nofresh_5
%**************************************************************************
%parameter
%clc;clear;
%cd /Users/yuannan/Desktop/sea ice in the okhotsk/ERA-japan/40years_data/original_data_program/
path(path,'/Users/yuannan/Desktop/sea ice in the okhotsk/in japan/m_map1.4/m_map');
name_m={'Jan.' 'Feb.' 'Mar.' 'Apr.' 'May.' 'Jun.' 'Jul.' 'Aug.' 'Sep.' 'Oct.' 'Nov.' 'Dec.'};
depth=parameter(1);lon=parameter(2);lat=parameter(3);name_m=parameter(4);
[LON,LAT]=meshgrid(lon,lat);
y=size(lon);x=size(lat);y=y(1,2);x=x(1,2);
layer_num=84;interval1=0.1;interval=10;dd=10;
p(1:x,1:y)=10.1325; %reference pressur e dbar
chose_month=1; %month
imonth=chose_month;%monthly-mean data
interval1=1.0/30.0;
lon_chosen_s=140;lon_chosen_e=146;lat_chosen_s=45;lat_chosen_e=55;
lat_profile_s=choose_lat(lat_chosen_s);lat_profile_e=choose_lat(lat_chosen_e);
lon_profile_s=choose_lon(lon_chosen_s);lon_profile_e=choose_lon(lon_chosen_e);

%%
%topography
fid_geo=fopen('coco_geo_grid.grd','r');
lon_old=100:0.1:270-0.1;lat_old=-10:0.1:67-0.1;
lon_new=100:1.0/30.0:270-1.0/30.0;lat_new=-10:1.0/30.0:67-1.0/30.0;
[l_old,t_old]=meshgrid(lon_old,lat_old); 
[l_new,t_new]=meshgrid(lon_new,lat_new);
c2_old=fread(fid_geo,1700*770,'real*4');
c2_old=reshape(c2_old,1700,770);c2_old=c2_old';
c2=interp2(l_old,t_old,c2_old,l_new,t_new);
c2(c2<-100000)=nan;
[gx,gy]=gradient(c2,interval1,interval1);
length_n=sqrt(gx.*gx+gy.*gy);
gx=gx./length_n;gy=gy./length_n; %gradient direction small--->large; right%downward:positive gradient
ay=sqrt(1./((gy.*gy)./(gx.*gx)+1));%tangent direction
ax=(-1.*ay.*gy)./gx;
%contour(LON,LAT,c2,'linewidth',0.3,'color','k');hold on;quiver(LON,LAT,ax,ay);%verify the tangent direction
%the backgroud vertical diffusivity

%%
%wind stress
fid1=fopen('/Volumes/Samsung_T5/monthly_mean_39_years_ECMWF/TAUX_monthly_39_real.grd','r');
fid2=fopen('/Volumes/Samsung_T5/monthly_mean_39_years_ECMWF/TAUY_monthly_39_real.grd','r');

lons_w=0;lone_w=359.25;lats_w=90;late_w=-90;
iter=0.75;lon_w=lons_w:iter:lone_w;lat_w=lats_w:-1*iter:late_w;
ix=size(lon_w);iy=size(lat_w);ix=ix(1,2);iy=iy(1,2);
[LON_w,LAT_w]=meshgrid(lon_w,lat_w);
f=1e-4; %s-1
rho_constant=1023.6; %kg/m3
imonth=1;

fseek(fid1,iy*ix*4*(imonth-1),-1);fseek(fid2,iy*ix*4*(imonth-1),-1);
taux=fread(fid1,ix*iy,'real*4');tauy=fread(fid2,ix*iy,'real*4');
taux1=reshape(taux,ix,iy);tauy1=reshape(tauy,ix,iy);
taux2=taux1';tauy2=tauy1';
taux_coco=griddata(LON_w,LAT_w,taux2,l_new,t_new);
tauy_coco=griddata(LON_w,LAT_w,tauy2,l_new,t_new);
[curlz,cav]=curl(LON,LAT,taux_coco,tauy_coco); %

My=-taux2/(f*rho_constant);
Mx=tauy2/(f*rho_constant);
Me2(:,:,imonth)=sqrt(My.*My+Mx.*Mx);
fclose(fid1);fclose(fid2);
%%
%read data
f_id=13;
[fid1,fid2,fid3,fid4,fid5,fid6,fid7,fid8,fid9,tit]=read_data(f_id); 
for layer=1:layer_num
%     fseek(fid1,y*x*4*(layer_num-layer)+y*x*layer_num*(imonth-1)*4,-1);
%     fseek(fid2,y*x*4*(layer_num-layer)+y*x*layer_num*(imonth-1)*4,-1);
    fseek(fid4,y*x*4*(layer-1)+y*x*layer_num*(imonth-1)*4,-1);
    fseek(fid5,y*x*4*(layer-1)+y*x*layer_num*(imonth-1)*4,-1);
    fseek(fid6,y*x*4*(layer-1)+y*x*layer_num*(imonth-1)*4,-1);
    fseek(fid7,y*x*4*(layer-1)+y*x*layer_num*(imonth-1)*4,-1);
%     t=fread(fid1,y*x,'real*4');t1=reshape(t,y,x);t1(t1<-10000)=nan;t_v(:,:,layer)=t1';
%     s=fread(fid2,y*x,'real*4');s1=reshape(s,y,x);s1(s1<-10000)=nan;s_v(:,:,layer)=s1';
%     rho(:,:,layer)=gsw_rho(s_v(:,:,layer),t_v(:,:,layer),p)-1000; %sa:g/kg ct degc
    u=fread(fid4,y*x,'real*4');u1=reshape(u,y,x);u1(u1<-10000)=nan;u_v(:,:,layer)=u1';
    v=fread(fid5,y*x,'real*4');v1=reshape(v,y,x);v1(v1<-10000)=nan;v_v(:,:,layer)=v1';
    %cons_a(:,:,layer)=u_v(:,:,layer).*gx(:,:)+v_v(:,:,layer).*gy(:,:);
    ahv=fread(fid6,y*x,'real*4');ahv1=reshape(ahv,y,x);ahv1(ahv1<-10000)=nan;ahv_v(:,:,layer)=ahv1';
    w=fread(fid7,y*x,'real*4');w1=reshape(w,y,x);w1(w1<-10000)=nan;w_v(:,:,layer)=w1';
end
%fclose(fid1);fclose(fid2);fclose(fid3);
fclose(fid4);fclose(fid5);
fclose(fid6);fclose(fid7);
%%
% u_v=u_v/100;
% v_v=v_v/100;
% w_v=w_v*24*60*60./100;
%%
%mixed layer
%-----------------------background-vertical-diffusivity-------------------%
for layer=1:layer_num
    if depth(1,layer_num-layer+1)<1500
        bvd(layer,1)=0.1+0.9*(1+tanh((depth(1,layer_num-layer+1)-1500)/750));
    else
        bvd(layer,1)=-1+2*(1+tanh((depth(1,layer_num-layer+1)-1500)/2000));
    end
end
figure(1)
plot(bvd(layer_num:-1:1,1),1:layer_num); 
set(gca,'Ytick',[1:10:84],...
    'YtickLabel',{'5854','1584','854','574','406','304','204','104','12'})
xlabel('Background Vertical Diffusivity of COCO(10^-^4 m^2/s)');
ylabel('Depth(m)');
close(figure(1));
%----------------------------mixed-layer-depth----------------------------% 
% %mixed layer: ahv_v>bvd
iii=1;jjj=1;
for ii=lat_profile_s:lat_profile_e
    for jj=lon_profile_s:lon_profile_e
        for ll=2:layer_num
%             if  ahv_v(ii,jj,ll)<bvd(ll,1)
%                 mix_layer(ii,jj)=ll;
%                 ahv_mix(ii,jj)=ahv_v(ii,jj,ll);
%                 break
            if  ahv_v(ii,jj,ll)<bvd(ll,1) && ahv_v(ii,jj,ll-1)>bvd(ll-1,1)
           % if  ahv_v(ii,jj,ll)<20 && ahv_v(ii,jj,ll-1)>20

                mix_layer(iii,jjj)=ll-1;
                break
    
            elseif ll>2 && isnan(ahv_v(ii,jj,ll))==1 && ahv_v(ii,jj,ll-1)>bvd(ll-1,1) %whole layer is the mixed layer
                mix_layer(iii,jjj)=ll-1;
                break
            else
                mix_layer(iii,jjj)=nan;
            end
        end
        jjj=jjj+1;
    end
    jjj=1;
    iii=iii+1;
end
depth2=flipud(depth');
depth1=depth2(2:end,1);
for ii=1:301
    for jj=1:181
        if isnan(mix_layer(ii,jj))
            mld(ii,jj)=nan;
        else
            mld(ii,jj)=depth1(mix_layer(ii,jj),1);
        end        
    end
end

%%
%------------------the water transport in the whole layer-----------------%
%---------------------------vertical-integration--------------------------%
% figure(4)
v_sum_ver(1:x,1:y,imonth)=0;
u_sum_ver(1:x,1:y,imonth)=0;
cons_sum_ver(1:x,1:y,imonth)=0;

for ii=lat_profile_s:lat_profile_e
    for jj=lon_profile_s:lon_profile_e
        for layer=2:layer_num
            if isnan(v_v(ii,jj,layer))
                v_sum_ver(ii,jj,imonth)=v_sum_ver(ii,jj,imonth)/depth(layer_num-layer+2);
                u_sum_ver(ii,jj,imonth)=u_sum_ver(ii,jj,imonth)/depth(layer_num-layer+2);
                break
            end
            v_v_a(ii,jj)=(v_v(ii,jj,layer)+v_v(ii,jj,layer-1))./2.*[depth(layer_num-layer+1)-depth(layer_num-layer+2)];%unit transfer cm/s->m/s
            v_sum_ver(ii,jj,imonth)=v_sum_ver(ii,jj,imonth)+v_v_a(ii,jj);
            u_v_a(ii,jj)=(u_v(ii,jj,layer)+u_v(ii,jj,layer-1))./2.*[depth(layer_num-layer+1)-depth(layer_num-layer+2)];%unit transfer cm/s->m/s
            u_sum_ver(ii,jj,imonth)=u_sum_ver(ii,jj,imonth)+u_v_a(ii,jj);
%             cons_v_a(ii,jj)=(cons_a(ii,jj,layer)+cons_a(ii,jj,layer-1))./200.*[depth(layer_num-layer+1)-depth(layer_num-layer+2)];%unit transfer cm/s->m/s
%             cons_sum_ver(ii,jj,imonth)=cons_sum_ver(ii,jj,imonth)+cons_v_a(ii,jj);

        end
    end
end

div(:,:,imonth)=divergence(LON,LAT,u_sum_ver,v_sum_ver);
%%
layer_div=3;%7m
for zzzz=1:84
    div(:,:,zzzz)=divergence(LON,LAT,u_v(:,:,zzzz),v_v(:,:,zzzz));
end
%%
div_b(1:2310,1:5100)=nan;
w_b(1:2310,1:5100)=nan;
u_b(1:2310,1:5100)=nan;
v_b(1:2310,1:5100)=nan;

range1=1600:2051;
range2=1100:1481;

for iiii=range1
    for jjjj=range2        
        for zzzz=2:84            
            if isnan(div(iiii,jjjj,zzzz)) && ~isnan(div(iiii,jjjj,zzzz-1))
                div_b(iiii,jjjj)=div(iiii,jjjj,zzzz-1);
                u_b(iiii,jjjj)=u_v(iiii,jjjj,zzzz-1);
                v_b(iiii,jjjj)=v_v(iiii,jjjj,zzzz-1);
                continue
            end
        end
    end
end

for iiii=range1

    for jjjj=range2
        
        for zzzz=3:84
            if isnan(w_v(iiii,jjjj,zzzz)) && ~isnan(w_v(iiii,jjjj,zzzz-1))
                w_b(iiii,jjjj)=w_v(iiii,jjjj,zzzz-1);
                continue
            end
        end
    end
    
end
%%
%cd /Volumes/Samsung_T5/paper_figures/
cd /Users/yuannan/Desktop/paper_figures/
%range2=1201:1351;
% range1_1=1651:10:1951; 
% range2_1=1201:10:1381;
% 
range1_1=1600:7:2051;
range2_1=1100:7:1481;

%--------------------------------draw-divergence--------------------------%
%v_sum_zon(:,:)=v_sum_zon(:,:)./1000000;
% v_sum_zon(v_sum_zon==0)=nan;
%subplot(3,4,imonth)
sub(1)=subplot(2,2,1);
%sub(1)=subplot(1,2,1);
%m_proj('miller','lon',[140 146],'lat',[45 55]);
m_proj('miller','lon',[141 145],'lat',[52 55]);
m_pcolor(LON(range1,range2),LAT(range1,range2),div(range1,range2,layer_div)./100000./100);
caxis([-0.5*10e-6 0.5*10e-6]);
colormap(sub(1),cmocean('curl'));
col1=colorbar;
set(col1,'ticks',[-0.05*10e-5 0 0.05*10e-5],'ticklabels',{'-5','0','5'},'FontName','Arial Rounded MT Bold','fontsize',10);
title(col1,{'DIV(10^-^6)'},'FontName','Arial Rounded MT Bold','fontsize',10)
hold on;m_quiver(LON(range1_1,range2_1),LAT(range1_1,range2_1),u_v(range1_1,range2_1,layer_div)./100,v_v(range1_1,range2_1,layer_div)./100,1.5,'color',[0 51 153]/255,'MaxHeadSize',4,'Markersize',10 ,'linewidth',4);
hold on;m_quiver(LON(range1_1,range2_1),LAT(range1_1,range2_1),u_v(range1_1,range2_1,layer_div)./100,v_v(range1_1,range2_1,layer_div)./100,1.5,'color',[102 204 255]/255,'MaxHeadSize',4,'Markersize',10 ,'linewidth',1);
hold on;m_gshhs_h('patch',[197 197 197]/255,'linewidth',3);
hold on;m_text(141.85,52.4,{'7m','Divergence','Jan.mean'},'FontName','Arial Rounded MT Bold','fontsize',15);
hold on;[c,h]=m_contour(LON(range1,range2),LAT(range1,range2),c2(range1,range2),[50 100 200],'linewidth',3,'color',[47 79 79]/255);
clabel(c,h,'fontsize',15,'labelspacing',1000,'FontName','Arial Rounded MT Bold','color',[47 79 79]/255);
% hold on;[c,h]=m_contour(LON(range1,range2),LAT(range1,range2),c2(range1,range2),[50 50],'linewidth',3,'color',[255 102 0]/255);
% clabel(c,h,'fontsize',15,'labelspacing',1000,'FontName','Arial Rounded MT Bold','color',[255 102 0]/255);
% hold on;[cc,hh]=m_contour(LON(range1,range2),LAT(range1,range2),c2(range1,range2),[100 100],'linewidth',3,'color',[245 222 179]/255);
% clabel(cc,hh,'fontsize',15,'labelspacing',1000,'FontName','Arial Rounded MT Bold','color',[245 222 179]/255);
% hold on;[ccc,hhh]=m_contour(LON(range1,range2),LAT(range1,range2),c2(range1,range2),[200 200],'linewidth',3,'color',[255 215 0]/255);
% clabel(ccc,hhh,'fontsize',15,'labelspacing',1000,'FontName','Arial Rounded MT Bold','color',[255 215 0]/255);
% 
hold on;m_quiver(142.3,53,5/100,0,1.5,'r','MaxHeadSize',5,'Markersize',10,'linewidth',2);
hold on;m_text(142.3,52.9,'5cm/s','FontName','Arial Rounded MT Bold','fontsize',10,'color','r');
m_grid('ytick',[45:1:55],'tickdir','out','linewi',4,'fontsize',15,'FontName','Arial Rounded MT Bold');
%m_text(142.7,50.5,'Sakhalin  Island','FontName','Arial Rounded MT Bold','fontsize',25,'rotation',90);
pos1=get(sub(1),'position');
set(sub(1),'position',[pos1(1,1),pos1(1,2)-0.05,0.4,0.4]);

sub(2)=subplot(2,2,2);
m_pcolor(LON(range1,range2),LAT(range1,range2),w_v(range1,range2,5)*24*60*60./100);
caxis([-5 5]);
colormap(sub(2),flipud(cmocean('tarn')));
col2=colorbar;
set(col2,'ticks',[-5 0 5],'ticklabels',{'-5','0','5'},'FontName','Arial Rounded MT Bold','fontsize',10);
title(col2,{'w(m/day)'},'FontName','Arial Rounded MT Bold','fontsize',10)
m_gshhs_h('patch',[197 197 197]/255,'linewidth',3);
hold on;m_text(141.9,52.4,{'18m','Vertical-','Velocity','Jan.mean'},'FontName','Arial Rounded MT Bold','fontsize',15);
hold on;[c,h]=m_contour(LON(range1,range2),LAT(range1,range2),c2(range1,range2),[50 100 200],'linewidth',3,'color',[47 79 79]/255);
clabel(c,h,'fontsize',15,'labelspacing',1000,'FontName','Arial Rounded MT Bold','color',[47 79 79]/255);
m_grid('ytick',[45:1:55],'tickdir','out','linewi',4,'fontsize',15,'FontName','Arial Rounded MT Bold');
%m_text(142.7,50.5,'Sakhalin  Island','FontName','Arial Rounded MT Bold','fontsize',25,'rotation',90);
pos2=get(sub(2),'position');
set(sub(2),'position',[pos2(1,1)-0.05,pos2(1,2)-0.05,0.4,0.4]);

sub(3)=subplot(2,2,3);
%sub(1)=subplot(1,2,1);
%m_proj('miller','lon',[140 146],'lat',[45 55]);
m_proj('miller','lon',[141 145],'lat',[52 55]);
m_pcolor(LON(range1,range2),LAT(range1,range2),div_b(range1,range2)./100000./100);
caxis([-0.5*10e-6 0.5*10e-6]);
colormap(sub(3),cmocean('curl'));
col3=colorbar;
set(col3,'ticks',[-0.05*10e-5 0 0.05*10e-5],'ticklabels',{'-5','0','5'},'FontName','Arial Rounded MT Bold','fontsize',10);
title(col3,{'DIV(10^-^6)'},'FontName','Arial Rounded MT Bold','fontsize',10)
hold on;m_quiver(LON(range1_1,range2_1),LAT(range1_1,range2_1),u_b(range1_1,range2_1)./100,v_b(range1_1,range2_1)./100,1.5,'color',[0 51 153]/255,'MaxHeadSize',4,'Markersize',10 ,'linewidth',4);
hold on;m_quiver(LON(range1_1,range2_1),LAT(range1_1,range2_1),u_b(range1_1,range2_1)./100,v_b(range1_1,range2_1)./100,1.5,'color',[102 204 255]/255,'MaxHeadSize',4,'Markersize',10 ,'linewidth',1);
hold on;m_gshhs_h('patch',[197 197 197]/255,'linewidth',3);
hold on;m_text(141.85,52.4,{'Bottom','Divergence','Jan.mean'},'FontName','Arial Rounded MT Bold','fontsize',15);

hold on;[c,h]=m_contour(LON(range1,range2),LAT(range1,range2),c2(range1,range2),[50 100 200],'linewidth',3,'color',[47 79 79]/255);
clabel(c,h,'fontsize',15,'labelspacing',1000,'FontName','Arial Rounded MT Bold','color',[47 79 79]/255);
hold on;m_quiver(142.3,53,5/100,0,1.5,'r','MaxHeadSize',5,'Markersize',10,'linewidth',2);
hold on;m_text(142.3,52.9,'5cm/s','FontName','Arial Rounded MT Bold','fontsize',10,'color','r');
m_grid('ytick',[45:1:55],'tickdir','out','linewi',4,'fontsize',15,'FontName','Arial Rounded MT Bold');
%m_text(142.7,50.5,'Sakhalin  Island','FontName','Arial Rounded MT Bold','fontsize',25,'rotation',90);
pos3=get(sub(3),'position');
set(sub(3),'position',[pos3(1,1),pos3(1,2)-0.05,0.4,0.4]);

sub(4)=subplot(2,2,4);
m_pcolor(LON(lat_profile_s:lat_profile_e,lon_profile_s:lon_profile_e),LAT(lat_profile_s:lat_profile_e,lon_profile_s:lon_profile_e),mix_layer(:,:));caxis([1 21]); 
pro_c=colorbar;
colormap(sub(4),flipud(cmocean('deep')));
set(pro_c,'Ticks',[1,3,5,7,9,11,13,15,17,19,21],...
    'Ticklabels',{'1','18','54','94','134','164','184','204','224','244','264'},...
    'FontName','Arial Black');
title(pro_c,'MLD(m)');
%hold on; m_contour(LON(lat_profile_s:lat_profile_e,lon_profile_s:lon_profile_e),LAT(lat_profile_s:lat_profile_e,lon_profile_s:lon_profile_e),mld,[30 50 100 150 200],'color','k','linewidth',2);
m_gshhs_h('patch',[197 197 197]/255,'linewidth',3);
hold on;m_text(141.9,52.4,{'Mixed','Layer','depth','Jan.mean'},'FontName','Arial Rounded MT Bold','fontsize',15);

hold on;[c,h]=m_contour(LON(range1,range2),LAT(range1,range2),c2(range1,range2),[50 50],'linewidth',3,'color',[255 102 0]/255);
clabel(c,h,'fontsize',15,'labelspacing',1000,'FontName','Arial Rounded MT Bold','color',[255 102 0]/255);
hold on;[cc,hh]=m_contour(LON(range1,range2),LAT(range1,range2),c2(range1,range2),[100 100],'linewidth',3,'color',[245 222 179]/255);
clabel(cc,hh,'fontsize',15,'labelspacing',1000,'FontName','Arial Rounded MT Bold','color',[245 222 179]/255);
hold on;[ccc,hhh]=m_contour(LON(range1,range2),LAT(range1,range2),c2(range1,range2),[200 200],'linewidth',3,'color',[255 215 0]/255);
clabel(ccc,hhh,'fontsize',15,'labelspacing',1000,'FontName','Arial Rounded MT Bold','color',[255 215 0]/255);

hold on;[ccc1,hhh1]=m_contour(LON(range1,range2),LAT(range1,range2),c2(range1,range2),[500 500],'linewidth',3,'color',[255 165 0]/255);
clabel(ccc1,hhh1,'fontsize',15,'labelspacing',1000,'FontName','Arial Rounded MT Bold','color',[255 165 0]/255);
hold on;[ccc2,hhh2]=m_contour(LON(range1,range2),LAT(range1,range2),c2(range1,range2),[1000 1000],'linewidth',3,'color',[255 250 205]/255);
clabel(ccc2,hhh2,'fontsize',15,'labelspacing',1000,'FontName','Arial Rounded MT Bold','color',[255 250 205]/255);

m_grid('ytick',[45:1:55],'tickdir','out','linewi',4,'fontsize',15,'FontName','Arial Rounded MT Bold');
%m_text(142.7,50.5,'Sakhalin  Island','FontName','Arial Rounded MT Bold','fontsize',25,'rotation',90);
pos4=get(sub(4),'position');
set(sub(4),'position',[pos4(1,1)-0.05,pos4(1,2)-0.05,0.4,0.4]);



set(gcf,'unit','centimeters','position',[0,0,40,40]);
set(gca,'linewidth',5);
print('GRL_2_new','-dtiff','-r600');

%clear linex liney;linex=143:0.1:144;liney(1:11)=53.5;
%hold on;m_line(linex,liney,'color','r','linewidth',3)
%m_grid('ytick',[],'xtick',[],'linewi',3);
% sub(2)=subplot(1,2,2);
% m_pcolor(LON(range1,range2),LAT(range1,range2),div_7(range1,range2)./100000);
% caxis([-0.5*10e-6 0.5*10e-6]);
% colormap(cmocean('curl'));
% colb=colorbar;
% set(colb,'ticks',[-0.05*10e-5 0 0.05*10e-5],'ticklabels',{'-5','0','5'},'FontName','Arial Rounded MT Bold','fontsize',15);
% title(colb,{'DIV','10^-^6'},'FontName','Arial Rounded MT Bold','fontsize',15)
% hold on
% m_quiver(LON(range1_1,range2_1),LAT(range1_1,range2_1),u_v(range1_1,range2_1,7),v_v(range1_1,range2_1,7),2,'color',[22 89 191]/255,'MaxHeadSize',5,'Markersize',10,'linewidth',2);
% m_gshhs_h('patch',[197 197 197]/255,'linewidth',1.5);
% hold on;m_text(142.2,49.8,{'Coastal','Bottom','(34m)'},'FontName','Arial Rounded MT Bold','fontsize',15);
% hold on;[c,h]=m_contour(LON(range1,range2),LAT(range1,range2),c2(range1,range2),[50 100 200],'linewidth',2,'color',[47 79 79]/255);
% clabel(c,h,'fontsize',15,'labelspacing',1000,'FontName','Arial Rounded MT Bold','color',[47 79 79]/255);
% hold on;m_quiver(140.5,52.5,10/100,0,2,'r','MaxHeadSize',5,'Markersize',10,'linewidth',2);
% m_text(140.5,52.3,'10cm/s','FontName','Arial Rounded MT Bold','fontsize',10,'color','r');
% m_grid('ytick',[45:1:55],'tickdir','out','linewi',3,'fontsize',15,'FontName','Arial Rounded MT Bold');
% m_text(142.7,50.5,'Sakhalin  Island','FontName','Arial Rounded MT Bold','fontsize',25,'rotation',90);

% sub(3)=subplot(1,3,3);
% m_pcolor(LON(range1,range2),LAT(range1,range2),div(range1,range2,1)./100000);
% caxis([-0.5*10e-6 0.5*10e-6]);
% colormap(cmocean('curl'));
% colb=colorbar;
% set(colb,'ticks',[-0.05*10e-5 0 0.05*10e-5],'ticklabels',{'-5','0','5'},'FontName','Arial Rounded MT Bold','fontsize',15);
% title(colb,{'DIV','10^-^6'},'FontName','Arial Rounded MT Bold','fontsize',15)
% hold on
% m_quiver(LON(range1_1,range2_1),LAT(range1_1,range2_1),u_sum_ver(range1_1,range2_1),v_sum_ver(range1_1,range2_1),2,'color',[0 0 128]/255,'MaxHeadSize',5,'Markersize',10,'linewidth',2);
% m_gshhs_h('patch',[197 197 197]/255,'linewidth',1.5);
% hold on;m_text(142.2,49.8,{'Vertical', 'Averaged'},'FontName','Arial Rounded MT Bold','fontsize',15);
% hold on;[c,h]=m_contour(LON(range1,range2),LAT(range1,range2),c2(range1,range2),[50 100 200],'linewidth',2,'color',[47 79 79]/255);
% clabel(c,h,'fontsize',15,'labelspacing',1000,'FontName','Arial Rounded MT Bold','color',[47 79 79]/255);
% hold on;m_quiver(140.5,52.5,10/100,0,2,'r','MaxHeadSize',5,'Markersize',10,'linewidth',2);
% m_text(140.5,52.3,'10cm/s','FontName','Arial Rounded MT Bold','fontsize',10,'color','r');
% m_grid('ytick',[45:1:55],'tickdir','out','linewi',3,'fontsize',15,'FontName','Arial Rounded MT Bold');
% m_text(142.5,50.5,'Sakhalin  Island','FontName','Arial Rounded MT Bold','fontsize',30,'rotation',90);
% 
% set(gcf,'unit','centimeters','position',[0,0,40,40]);
% %set(sub(1),'position',[0 0.11 0.3019 0.8150]);
% print('w_54','-dtiff','-r600');
%print('notide_whole_layer_small_cross_isobath','-dtiff','-r300');
% 
% end
% set(gcf,'unit','centimeters','position',[10,15,40,40]);
% suptitle('Ekman transport using velocity');
% %save v_sum_ver v_sum_ver
%%

figure(2) %temp
%m_proj('miller','lon',[143 144.4],'lat',[53 54]);
m_proj('miller','lon',[140 146],'lat',[45 55]);
m_pcolor(LON,LAT,t_v(:,:,1));
caxis([-2 0]);
pro_c=colorbar;
set(pro_c,'FontName','Arial Black');
hold on
[c,h]=m_contour(LON,LAT,c2,'linewidth',1,'color','k');
set(h,'levellist',[50 100 150 250]);
clabel(c,h,'fontsize',10,'labelspacing',1000);
hold on
[c1,h1]=m_contour(LON,LAT,t_v(:,:,1),':','linewidth',2,'color',[227 23 13]/255);
set(h1,'levellist',[0 -1.4 -1.5 -1.6 -1.7]);
clabel(c1,h1,'fontsize',15,'labelspacing',1000);
colormap(flipud(othercolor('Accent5')));
%title('Divergence-Jan. surface','fontsize',15,'FontName','Arial Black');
m_gshhs_h('patch',[.7 .7 .7],'linewidth',1.5);
m_grid('ytick',[45:1:55],'tickdir','out','linewi',3,'fontsize',15,'FontName','Arial Black');
set(gcf,'unit','centimeters','position',[10,15,40,40]);
print('temp','-dtiff','-r600');

%%
figure(3) %salt
%m_proj('miller','lon',[143 144.4],'lat',[53 54]);
m_proj('miller','lon',[140 146],'lat',[45 55]);
m_pcolor(LON,LAT,s_v(:,:,1));
caxis([15 35]);
pro_c=colorbar;
set(pro_c,'FontName','Arial Black');
hold on
[c,h]=m_contour(LON,LAT,c2,'linewidth',1,'color','k');
set(h,'levellist',[50 100 150 250]);
clabel(c,h,'fontsize',10,'labelspacing',1000);
hold on
[c1,h1]=m_contour(LON,LAT,s_v(:,:,1),':','linewidth',2,'color',[227 23 13]/255);
set(h1,'levellist',[15 20 25 27 29 31 33 35]);
clabel(c1,h1,'fontsize',15,'labelspacing',1000);
colormap(othercolor('Accent5'));
%title('Divergence-Jan. surface','fontsize',15,'FontName','Arial Black');
m_gshhs_h('patch',[.7 .7 .7],'linewidth',1.5);
m_grid('ytick',[45:1:55],'tickdir','out','linewi',3,'fontsize',15,'FontName','Arial Black');
set(gcf,'unit','centimeters','position',[10,15,40,40]);
print('sal','-dtiff','-r600');

%%
figure(4) %rho
%m_proj('miller','lon',[143 144.4],'lat',[53 54]);
m_proj('miller','lon',[140 146],'lat',[45 55]);
m_pcolor(LON,LAT,rho(:,:,1));
caxis([15 27]);
pro_c=colorbar;
set(pro_c,'FontName','Arial Black');
hold on
[c,h]=m_contour(LON,LAT,c2,'linewidth',1,'color','k');
set(h,'levellist',[10 20 30 40 50 100 150 250]);
clabel(c,h,'fontsize',10,'labelspacing',1000);
hold on
[c1,h1]=m_contour(LON,LAT,rho(:,:,1),':','linewidth',2,'color','r');
set(h1,'levellist',[15 20 21 22 23 24 25 26]);
clabel(c1,h1,'fontsize',15,'labelspacing',1000);
colormap(othercolor('Accent5'));
%title('Divergence-Jan. surface','fontsize',15,'FontName','Arial Black');
m_gshhs_h('patch',[.7 .7 .7],'linewidth',1.5);
m_grid('ytick',[45:1:55],'tickdir','out','linewi',3,'fontsize',15,'FontName','Arial Black');
set(gcf,'unit','centimeters','position',[10,15,40,40]);
%print('rho','-dtiff','-r600');

%%
figure(5) %wind
m_proj('miller','lon',[140 146],'lat',[45 55]);
m_pcolor(LON,LAT,curlz);
caxis([-0.1 0.1]);
pro_c=colorbar;
set(pro_c,'FontName','Arial Black');
colormap(othercolor('Accent5'));
hold on;m_quiver(LON(1:15:end,1:15:end),LAT(1:15:end,1:15:end),taux_coco(1:15:end,1:15:end),tauy_coco(1:15:end,1:15:end),'linewidth',2,'color',[128 138 135]/255);
m_gshhs_h('patch',[.7 .7 .7],'linewidth',1.5);
m_grid('ytick',[45:1:55],'tickdir','out','linewi',3,'fontsize',15,'FontName','Arial Black');
hold on
h4=m_quiver(142.5,49.8,1*cosd(50),0,0,'linewidth',1);
set(h4,'maxheadsize',1.2,'color','k');
h5=m_text(142.5,49.5,'1 pa');
set(h5,'fontsize',15);
set(gcf,'unit','centimeters','position',[10,15,40,40]);
print('wind_stress','-dtiff','-r600');

%%
figure(6)%MLD
m_proj('miller','lon',[140 146],'lat',[45 55]);
m_pcolor(LON(lat_profile_s:lat_profile_e,lon_profile_s:lon_profile_e),LAT(lat_profile_s:lat_profile_e,lon_profile_s:lon_profile_e),mix_layer(:,:));caxis([1 21]); 
pro_c=colorbar;
%colormap(othercolor('Accent5'));
% set(pro_c,'Ticks',[2,4,6,8,10,12,14,16,18,20],...
%           'Ticklabels',{'3','12','24','44','64','84','104','124','144','164'},...
%           'FontName','Arial Black');
set(pro_c,'Ticks',[1,3,5,7,9,11,13,15,17,19,21],...
    'Ticklabels',{'1','18','54','94','134','164','184','204','224','244','264'},...
    'FontName','Arial Black');
title(pro_c,'MLD(m)');
hold on
[c,h]=m_contour(LON,LAT,c2,'linewidth',2,'color','k');
%set(h,'levellist',[100 200 300 400 500 1000]);
set(h,'levellist',[50 100 150 250]);
clabel(c,h,'fontsize',15,'labelspacing',1000);
%clabel(c,h,'manual','fontsize',15,'color','k');
%title('the Mixed Layer Depth-JAN','fontsize',15,'FontName','Arial Black');
m_gshhs_h('patch',[.7 .7 .7],'linewidth',1.5);
m_grid('ytick',[45:1:55],'tickdir','out','linewi',3,'fontsize',15,'FontName','Arial Black');
set(gcf,'unit','centimeters','position',[10,15,40,40]);
%print('notide_MLD_new','-dtiff','-r600');

